home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asm_subr.arc / BCD2I16 < prev    next >
Encoding:
Text File  |  1985-12-22  |  2.0 KB  |  90 lines

  1. ;-------------------------bcd2i16 routine begins--------------------------+
  2. ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
  3. ;         page : 68
  4. ;
  5. ; NAME BCD2I16
  6. ; ROUTINE FOR converting internal BCD format to internal 16-bit binary
  7. ;
  8. ; FUNCTION: This routine converts from internal BCD format to internal
  9. ; binary format.
  10. ;
  11. ; INPUT: Upon entry a 36-digit number is contained in an 18-digit BCD
  12. ; buffer called BCDBUFF.
  13. ;
  14. ; OUTPUT: A 16-bit binary number is returned in DX
  15. ;
  16. ; REGISTERS USED:  Only DX is modified.  DX is used for output.
  17. ;
  18. ; SEGMENTS REFERENCED:  DATAS is a data segment which contains the buffer
  19. ; BDCBUFF
  20. ;
  21. ; ROUTINES CALLED:  None
  22. ; SPECIAL NOTES: None
  23. ;
  24. ; ROUTIINE TO CONVERT FROM INTERNAL BCD TO INTERNAL 16-BIT BINARY
  25. ;
  26. bcd2i16    proc    far
  27. ;
  28.     push    ds        ; save registers
  29.     push    si
  30.     push    cx
  31.     push    ax
  32. ;
  33. ; set up the data segment
  34.     mov    ax,datas    ; point to data segment
  35.      mov    ds,ax
  36. ;
  37. ; set up a loop
  38.     mov    cx,18        ; initialize counter
  39.     lea    si,bcdbuff    ; point to buffer
  40.     add    si,17        ; point to end of bcdbuff
  41.     mov    dx,0        ; init DX to 0
  42. ;
  43. bcd2i161:
  44.     push    cx        ; save loop count
  45.     mov    al,[si]        ; get BCD byte
  46.     dec    si        ; point to next one
  47.     mov    bl,al        ; save it
  48. ;
  49. ; upper digit
  50.     mov    cl,4        ; for a count of 4
  51.     rol    al,cl        ; rotate byte
  52.     and    al,0Fh        ; just the digit
  53.     cbw            ; convert to word
  54. ;
  55.     push    ax        ; save the digit
  56.     mov    ax,dx
  57.     mov    cx,10        ; multiplier of 10
  58.     mul    cx        ; multiply
  59.     mov    dx,ax        ; result in dx
  60.     pop    ax        ; restore digit
  61. ;
  62.     add    dx,ax        ; add in digit
  63. ;
  64.     moov    al,bl        ; byte back
  65. ;
  66. ; lower digit
  67.     and     al,0Fh        ; just the digit
  68.     cbw            ; convert to word
  69. ;
  70.     push    ax        ; save digit
  71.     mov    ax,dx
  72.     mov    cx,10        ; multiplier of 10
  73.     mul    cx        ; multiply
  74.     mov    dx,ax        ; result in DX
  75.     pop    ax        ; restore digit
  76. ;
  77.     add    dx,ax        ; add in digit
  78. ;
  79.     pop    cx        ; restore loop count
  80.     loop    bcd2i161
  81. ;
  82.     pop    ax        ; restore registers
  83.     pop    cx
  84.     pop    si
  85.     pop    ds
  86.     ret            ; return
  87. ;
  88. bcd2i16    endp
  89. ;-------------------------bcd2i16 routine ends---------------------------+
  90.